﻿/* 
raveBind({
    url: "/rave", 
    data: '<raveTranslateConfig key="umbraco_bing" cache="0" responseType="json"><url>http://www.bing.com/search?q=umbraco</url><xslt xsltPath="xslt/bingsample.xslt"><postRegex regularExpression="\\s+" replaceString=" " /></xslt></raveTranslateConfig>', 
    retType: "json", 
    outputSelector: "#outputId"
 });

url - the url to post.  should be relative to avoid cross domain issues - "/rave"
data - xml with the query info
retType - "xml" or "json"
outputSelector - jQuery selector syntax for hte following call.  $(outputSelector).html(result);
*/
function raveBind(config) {
    var fn = "$(\"" + config.outputSelector + "\").html(result.response); $(\"" + config.outputSelector + "\").fadeIn();";

    $.ajax({
        type: "POST",
        url: config.url,
        data: config.data,
        dataType: config.retType,
        success: function (result) {
            var fnLocal;
            if (result != null) {
                json = $.parseJSON(result);
                if (config.callback)
                    config.callback(json);
                else {
                    fnLocal = new Function("result", fn);
                    fnLocal(json);
                }
            }
        }
    });
}

function raveKeyBind(config) {
    var fn = "$(\"" + config.outputSelector + "\").html(result.response); $(\"" + config.outputSelector + "\").fadeIn();";

    $.ajax({
        type: "GET",
        url: config.url,
        dataType: config.retType,
        success: function (result) {
            var fnLocal;
            if (result != null) {
                json = $.parseJSON(result);
                if (config.callback)
                    config.callback(json);
                else {
                    fnLocal = new Function("result", fn);
                    fnLocal(json);
                }
            }
        }
    });
}